//<!--begin
/*
 * Copyright (C) 2000-2007 Wang Pengcheng <wpc0000@gmail.com>
 * Licensed to the Wang Pengcheng under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The LGPL licenses this file to You under the GNU Lesser General Public
 * Licence, Version 2.0  (the "License"); you may not use this file except in
 * compliance with the License.  You may obtain a copy of the License at
 *
 *     http://www.gnu.org/licenses/lgpl.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * 28 Aug 2007
 */
package $PACKAGE.databaseAction;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.ibatis.common.resources.Resources;

import java.io.Reader;
import java.io.IOException;
import java.util.*;
import java.sql.SQLException;

import $PACKAGE.database.$DATABean;

public class $DATAAction {

	/**
	 * SqlMapClient instances are thread safe, so you only need one. In this
	 * case, we'll use a static singleton. So sue me. ;-)
	 */
	private static SqlMapClient sqlMapper;

	/**
	 * It's not a good idea to put code that can fail in a class initializer,
	 * but for sake of argument, here's how you configure an SQL Map.
	 */
	static {
		try {
			Reader reader = Resources
					.getResourceAsReader("$PKGURL/databaseAction/SQLMapConfig.xml");
			sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		} catch (IOException e) {
			throw new RuntimeException(
					"Something bad happened while building the SqlMapClient instance."
							+ e, e);
		}
	}

	//<!--select all
	public static List<$DATABean> selectAll$DATABeans() throws SQLException {
		return sqlMapper.queryForList("selectAll$DATABeans");
	}

	//<!--select one list
	public static List<$DATABean> select$DATABeansBy$METHODNAME($TYPE $NAME) throws SQLException {
		return sqlMapper.queryForList("select$DATABeansBy$METHODNAME",$NAME);
	}	

	//<!--select one object
	public static $DATABean select$DATABeanBy$METHODNAME($TYPE $NAME) throws SQLException {
		return ($DATABean) sqlMapper.queryForObject("select$DATABeanBy$METHODNAME", $NAME);
	}

	//<!--insert
	public static int insert$DATABean($DATABean $DATABean) throws SQLException {
		return (Integer)sqlMapper.insert("insert$DATABean", $DATABean);
	}

	//<!--update
	public static void update$DATABean($DATABean $DATABean) throws SQLException {
		sqlMapper.update("update$DATABean", $DATABean);
	}

	//<!--delete one
	public static void delete$DATABeanBy$METHODNAME($TYPE $NAME) throws SQLException {
		sqlMapper.delete("delete$DATABeanBy$METHODNAME", $NAME);
	}

	//<!--delete all
	public static void deleteAll$DATABeans() throws SQLException {
		sqlMapper.delete("deleteAll$DATABeans");
	}
	
	//<!--end
}
